package com.helasasa.maxfunds.lineofcredit.cashloan.splash.http

import android.content.Context
import com.helasasa.maxfunds.lineofcredit.cashloan.ProjectApplication
import org.json.JSONObject

/**
 * 埋点
 */
fun Context.hitPointHelasasa(
    type: String,
    remark: String = "",
    isPageStart: Boolean = false,
    isPageEnd: Boolean = false
) {

    // 格式化type
    var typeFormat = type
    val startPrefix = ProjectApplication.mProduct + "_"
    if (type.startsWith(startPrefix, true)) {
        typeFormat = type
    } else {
        typeFormat = startPrefix + type
    }
    if (isPageStart) {
        typeFormat += "_START"
    } else if (isPageEnd) {
        typeFormat += "_END"
    }
    typeFormat = typeFormat.uppercase()

    // 组装参数
    val context = ProjectApplication.context
    val action = hashMapOf<String, Any>().createApiActionHelasasa()
    action["path"] = "kf2iNkXLE9e0hwT0jl9Sg"
    action["type"] = typeFormat
    action["remark"] = remark

    context.doPostRequestHelasasa(action, object : IApiProcessHelasasaCallback {
        override fun onApiReady() {
        }

        override fun onApiDone(jsonObject: JSONObject) {
        }

        override fun onApiError(code: String, errMsg: String) {
        }
    })
}